package com.accesshollywood.components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

public class AnimateSwing implements ActionListener {
	final Double	start;
	final Double	end;
	final Double	step;
	Double			current;
	AnimSwing		animClass;
	Timer			animTimer;

	public AnimateSwing(Number start, Number end, Number step, AnimSwing animClass) {
		this.start = start.doubleValue();
		this.end = end.doubleValue();
		this.step = step.doubleValue();
		this.current = start.doubleValue();
		this.animClass = animClass;
	}

	public void startTimer(Timer animTimer) {
		this.animTimer = animTimer;
		animTimer.start();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		current += step;
		if ((end > start && (current <= start || current >= end)) || (end < start && (current >= start || current <= end))) {
			current = end;
			animTimer.stop();
			animTimer = null;
			animClass.animateFinished();
		}
		animClass.animateParameter(current);
	}

}
